<div class="loading-container"><div class="loader"></div></div>

<div class="wrapper wrapper-shadow wrapper-list"> 
	<!-- list data wrapper -->
   	<div class="result-wrapper no-padding">
    	<div class="result-body">
    		<div class="tabs">
          <ul class="nav nav-tabs widget no-margin-bottom">
          	<li>
            	<a href="#tab-content" data-toggle="tab" onclick="handlerStatus(this, 'todo')" data-table-toggle="jQuery('.btn-group-operator').show()" data-table-target="#table-contract" data-form-search="#search-form-contract"> 
            		<span class="menu-icon"><i class="fa fa-check-circle-o"></i></span> 未完成
            	</a>
            </li>
            <li class="active">
            	<a href="#tab-content" data-toggle="tab" onclick="handlerStatus(this, '0')" data-table-toggle="jQuery('.btn-group-operator').show()" data-table-target="#table-contract" data-form-search="#search-form-contract"> 
            		<span class="menu-icon"><i class="fa fa-check-circle-o"></i></span> 执行中 
            	</a>
            </li>
            <li>
            	<a href="#tab-content" data-toggle="tab" onclick="handlerStatus(this, 'close')" data-table-toggle="jQuery('.btn-group-operator').hide()" data-table-target="#table-contract" data-form-search="#search-form-contract"> 
            		<span class="menu-icon"><i class="fa fa-pause-circle-o"></i></span> 未启用 
            	</a>
            </li>
            <li>
            	<a href="#tab-content" data-toggle="tab" onclick="handlerStatus(this, 'pause')" data-table-toggle="jQuery('.btn-group-operator').hide()" data-table-target="#table-contract" data-form-search="#search-form-contract"> 
            		<span class="menu-icon"><i class="fa fa-pause-circle-o"></i></span> 已暂停 
            	</a>
            </li>
            <li>
            	<a href="#tab-content" data-toggle="tab" onclick="handlerStatus(this, 'finish')" data-table-toggle="jQuery('.btn-group-operator').hide()" data-table-target="#table-contract" data-form-search="#search-form-contract"> 
            		<span class="menu-icon"><i class="fa fa-stop-circle-o"></i></span> 已结束 
            	</a>
            </li>
            <li>
            	<a href="#tab-content" data-toggle="tab" onclick="handlerStatus(this, 'refund')" data-table-toggle="jQuery('.btn-group-operator').hide()" data-table-target="#table-contract" data-form-search="#search-form-contract"> 
            		<span class="menu-icon"><i class="fa fa-stop-circle-o"></i></span> 已退费 
            	</a>
            </li>
          </ul>
          <div class="tab-content no-border xs-padding">
            <div class="tab-pane active" id="tab-content">
            	<div id="toolbar" class="btn-group btn-group-operator">
						    <button type="button" id="export" class="btn btn-warning" onclick="handlerExport();">
				        	<i class="glyphicon glyphicon-export"></i> 导出
						    </button>
						    <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="btn_adviser">
						    	<i class="glyphicon glyphicon-random"></i> 分配
						 		</button>
								<ul class="dropdown-menu" id="list-adviser"></ul>
							</div>
            	<table data-ajax="handlerSearch" 
         					 	 data-method="post" 
         					 	 data-search="true" 
         					 	 data-toolbar="#toolbar" 
         					 	 data-id-field="id" 
         					 	 data-unique-id="id" 
         					 	 data-pagination="true" 
         					 	 data-show-toggle="true" 
         					 	 data-show-refresh="true" 
         					 	 data-show-columns="true" 
         					 	 data-check-on-init="true" 
         					 	 data-click-to-select="true" 
         					 	 data-side-pagination="server" 
         					 	 data-mobile-responsive="true" 
         					 	 data-event-onload="handlerSuccess" 
         					 	 data-form-search="#search-form-contract" id="table-contract" class="bootstrap-table">
								<thead>
									<tr>
										<th data-checkbox="true"></th>
										<th data-field="id" 					data-visible="false" data-switchable="false">ID</th>
										<th data-field="username" 		data-align="center" data-sortable="true">顾问</th>
										<th data-field="student" 			data-align="center" >会员</th>
										<th data-field="moonage" 			data-align="center" data-sortable="true">月龄</th>
										<th data-field="relation" 		data-align="center" >家长</th>
										<th data-field="mobile" 			data-align="center" >手机</th>
										<th data-field="createDate" 	data-align="center" data-sortable="true">签约时间</th>
										<th data-field="validity" 		data-align="center" >有效期</th>
										<th data-field="buyitem" 			data-align="center" >签约类型</th>
										<th data-field="totalsPrice" 	data-align="center" data-sortable="true">合同金额</th>
										<th data-field="rested" 			data-align="center" data-sortable="true">剩余课时</th>
										<th data-field="operator" 		data-align="center" data-width="160" data-formatter="renderOperator" data-table-target="contract">操作</th>
									</tr>
								</thead>
							</table>
            </div>
          </div>
        </div>
    	</div>
   	</div>

	<!-- form editor wrapper -->
	<div class="editor-wrapper">
	
	</div>
</div>
<!-- PAGE CONTENT END =============================================== -->

<!-- PAGE MODAL START =============================================== -->
<!-- 顾问分配 -->
<div class="modal fade" id="adviser-table-modal" tabindex="-1" role="dialog" aria-labelledby="adviser-table-modal-label" data-backdrop="static">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="关闭"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="adviser-table-modal-label">选择顾问</h4>
      </div>
      <div class="modal-body">
        <table data-ajax="handlerSearch" 
       				 data-method="post" 
						 	 data-id-field="id" 
						 	 data-unique-id="id" 
							 data-pagination="true" 
							 data-check-on-init="true" 
							 data-click-to-select="true" 
							 data-side-pagination="server" 
							 data-mobile-responsive="true" 
							 data-event-onload="handlerLoaded" 
							 data-form-search="#search-form-adviser" id="table-adviser" class="bootstrap-table">
					<thead>
						<tr>
							<th data-radio="true"></th>
							<th data-field="id" data-visible="false">ID</th>
							<th data-field="name" 		data-align="center" >姓名</th>
							<th data-field="mobile" 	data-align="center" >手机</th>
							<th data-field="newadds" 	data-align="center" >当月新增客户</th>
							<th data-field="follows" 	data-align="center" >当月跟进客户</th>
							<th data-field="members" 	data-align="center" >当月签约客户</th>
						</tr>
					</thead>
				</table>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" onclick="handlerAdviser()">确认</button>
      </div>
    </div>
  </div>
</div>
<!-- PAGE MODAL END ================================================= -->

<!-- 查询表单 ========================================================= -->
<form id="search-form-contract" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.view.ContractView">
			<input type="hidden" name="status" value="0" 				data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" name="invalid" value="F" 			data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" data-search-sort="createDate" 	data-search-order="desc"/>
			<input type="hidden" data-search-sort="id" 					data-search-order="asc"/>
</form>
<form id="search-form-adviser" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.view.AdviserView">
			<input type="hidden" name="status" value="0" 				data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" name="invalid" value="F" 			data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" data-search-sort="createDate" 	data-search-order="desc"/>
			<input type="hidden" data-search-sort="id" 					data-search-order="asc"/>
</form>
<form id="search-form-history" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.view.ContractView">
			<input type="hidden" name="id" value="0" 						data-search-group="and" data-search-operation="NE" data-foreign-id="data-foreign-id"/>
			<input type="hidden" name="invalid" value="F" 			data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" name="studentid" value="0" 		data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" data-search-sort="createDate" 	data-search-order="desc"/>
			<input type="hidden" data-search-sort="id" 					data-search-order="asc"/>
</form>
<form id="search-form-buyinfo" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.contract.Buyinfo" 
			data-template-target=".editor-body-buyinfo" data-template-id="#edit-buyinfo-template" 
			data-template-path="/miwawa/content/esm/contract/template.html">
			<input type="hidden" name="status" value="0" data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" name="contractId" value="0" data-search-group="and" data-search-operation="EQ"/>
</form>
<form id="search-form-payinfo" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.contract.Payinfo" 
			data-template-target=".editor-body-payinfo" data-template-id="#edit-payinfo-template" 
			data-template-path="/miwawa/content/esm/contract/template.html">
			<input type="hidden" name="status" value="0" data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" name="invalid" value="F" data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" name="contractId" value="0" data-search-group="and" data-search-operation="EQ"/>
</form>
<!-- 删除 表单 ========================================================= -->
<form id="reback-form-contract" action="/miwawa/{dbname}/contract/reback" method="post" name="com.app.miwawa.api.esm.entity.contract.Contract"></form>
<form id="remove-form-contract" action="/miwawa/{dbname}/common/remove" method="post" name="com.app.miwawa.api.esm.entity.contract.Contract"></form>
<!-- 导出  -->
<form id="export-form" action="/miwawa/{dbname}/common/procedure/export" method="post">
	<input type="hidden" name="name" value="合同表"/>
</form>

<!-- Javascript ===================================================== -->
<script src="/miwawa/resources/lib/miwawa/1.0.2/js/core/requirejs/require.js"></script>

<script th:inline="javascript">
/*<![CDATA[*/
<!--
	var auths = /*[[${data.result.auths}]]*/;
	var authstr = "";
	/* ===================================== */
	/* 列表页面 */
	/* ===================================== */
	
	// 注册列表核心组件
	jQuery(function(){
		require(['/miwawa/resources/lib/miwawa/1.0.2/js/core/module/app/simple.js'], function(simple){
			simple(['registerForm','registerTable','registerWidget']);
		});
		
		var array = [];
		for(var i in auths){
			array.push(auths[i].code);
		}
		authstr = array.join(",");
	});
	
	// 导出
	function handlerExport(){
		var action = jQuery("#export-form").attr("action").replace("{dbname}", dbname);
		jQuery("#export-form").attr("action", action);
		jQuery(":hidden[name='params[html]']","#export-form").remove();
		jQuery("#export-form").append('<input type="hidden" name="params[html]"/>');
		jQuery(":hidden[name='params[html]']","#export-form").val(jQuery("#table-a2").html());
		jQuery("#export-form")[0].submit();
	}
	
	// TODO 顾问列表加载完后调用
	function handlerLoaded(data){
		// 创建顾问下拉选单
		jQuery("#list-adviser").append(function(){
			var html = "";
			jQuery.each(data.rows,function(i,adviser){
				html+="<li><a href='javascript:void(0);' class='selected-dropdown' data-selected-id='"+adviser.id+"'>"+adviser.name+"</a></li>"
			});
			return html;
		});
		
		// 绑定顾问下拉选单的选中时间
		jQuery('#list-adviser').delegate('a.selected-dropdown', 'click', function() {
			var rows = jQuery("#table-contract").bootstrapTable("getSelections");
			if(rows.length <= 0){
				jQuery.message.warning("请选择要分配顾问的会员！");
			}else{
				handlerSelected(this);
			}
		});
		
		// 分配销售顾问
		function handlerSelected(_this){
			var ids = [];
			var url = "/miwawa/{dbname}/contract/update/{ids}".replace("{dbname}", dbname);
			var rows = jQuery("#table-contract").bootstrapTable("getSelections");
			
			jQuery.each(rows, function(index, row){
				ids.push(row.id);			
			});
			
			jQuery.ajaxsend({
				url:url.replace("{ids}", ids.join(",")),
				data:{
					"userid":jQuery(_this).data("selected-id"),
					"username":jQuery(_this).text()
				},
				success:function(data){
					if(data && data["success"]) {
						jQuery("#table-contract").bootstrapTable('refresh');
					}
				}
			});
		}
	};

	function handlerPrint(){
		
	}
	
	function renderOperator(value, row, index){
		var operator = "";
		
		if(row.status == "0"){
	 		if(authstr.indexOf("miwawa.esm.contract.editor") > -1){
	 			operator += "<a class='btn btn-info	  btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='edit.html' data-toggle='tooltip' data-placement='top' title='查看及编辑'> <i class='ion-compose'></i> </a>";
	 		}else if(authstr.indexOf("miwawa.esm.contract.viewer") > -1){
	 			operator += "<a class='btn btn-info	  btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='view.html' data-toggle='tooltip' data-placement='top' title='查看'> <i class='ion-compose'></i> </a>";
	 		}
	 		if(authstr.indexOf("miwawa.esm.contract.resign") > -1){
	 			operator += "<a class='btn btn-success btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='sign.html' data-toggle='tooltip' data-placement='top' title='续费'> <i class='icon-loop'></i> </a>";
	 		}
	 		
	 			operator += "<a class='btn btn-primary btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='history.html' data-toggle='tooltip' data-placement='top' title='查看签到历史'> <i class='fa fa-eye'></i> </a>";
	 		
	 		if(authstr.indexOf("miwawa.esm.contract.stoper") > -1){
	 			operator += "<a class='btn btn-warning btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='stop.html' data-toggle='tooltip' data-placement='top' title='停课'> <i class='icon-control-pause'></i> </a>"; 
	 		}
	 		if(authstr.indexOf("miwawa.esm.contract.refund") > -1){
	 			operator += "<a class='btn btn-danger  btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='exit.html' data-toggle='tooltip' data-placement='left' title='退费及终止'> <i class='icon-close'></i> </a>"; 
	 		}
	 	}else if(row.status == "close"){
	 		if(authstr.indexOf("miwawa.esm.contract.viewer") > -1){
	 			operator += "<a class='btn btn-info	  btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='view.html' data-toggle='tooltip' data-placement='top' title='查看'> <i class='ion-compose'></i> </a>";
	 		}
	 		if(authstr.indexOf("miwawa.esm.contract.enable") > -1){
	 			operator += "<a class='btn btn-success btn-xs btn-table-op' onclick='handlerStart(this,\""+row.id+"\",\""+row.studentid+"\",\""+row.item+"\")' data-table-source='#table-contract' data-form-source='#reback-form-contract' data-toggle='tooltip' data-placement='top' title='启用' data-custom='true'> <i class='fa fa-play-circle-o'></i> </a>";
	 		}
	 		if(authstr.indexOf("miwawa.esm.contract.remove") > -1){
	 			operator += "<a class='btn btn-danger  btn-xs btn-table-op' onclick='handlerRemove(this,\""+row.id+"\")' data-table-source='#table-contract' data-form-source='#remove-form-contract' data-toggle='tooltip' data-placement='top' title='删除'> <i class='fa fa-trash'></i> </a>";
	 		}
		}else if(row.status == "pause"){
			if(authstr.indexOf("miwawa.esm.contract.viewer") > -1){
	 			operator += "<a class='btn btn-info	  btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='view.html' data-toggle='tooltip' data-placement='top' title='查看'> <i class='ion-compose'></i> </a>";
	 		}
	 		
	 		operator += "<a class='btn btn-primary	  btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='history.html' data-toggle='tooltip' data-placement='top' title='查看签到历史'> <i class='fa fa-eye'></i> </a>";
	 		
			if(authstr.indexOf("miwawa.esm.contract.reopen") > -1){
	 			operator += "<a class='btn btn-success btn-xs btn-table-op' onclick='handlerReback(this,\""+row.id+"\")' data-table-source='#table-contract' data-form-source='#reback-form-contract' data-toggle='tooltip' data-placement='top' title='恢复' data-custom='true'> <i class='fa fa-reply'></i> </a>";
	 		}
		}else if(row.status == "todo"){
			if(authstr.indexOf("miwawa.esm.contract.viewer") > -1){
	 			operator += "<a class='btn btn-info	  btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='edit.html' data-toggle='tooltip' data-placement='top' title='查看及编辑'> <i class='ion-compose'></i> </a>";
	 		}
			if(authstr.indexOf("miwawa.esm.contract.remove") > -1){
	 			operator += "<a class='btn btn-danger  btn-xs btn-table-op' onclick='handlerRemove(this,\""+row.id+"\")' data-table-source='#table-contract' data-form-source='#remove-form-contract' data-toggle='tooltip' data-placement='top' title='删除'> <i class='fa fa-trash'></i> </a>";
	 		}
		}else if(row.status == "finish" || row.status == "refund"){
			if(authstr.indexOf("miwawa.esm.contract.viewer") > -1){
	 			operator += "<a class='btn btn-info	  btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='view.html' data-toggle='tooltip' data-placement='top' title='查看'> <i class='ion-compose'></i> </a>";
	 		}
 			
	 		operator += "<a class='btn btn-primary	  btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-contract' data-editor-path='/miwawa/content/esm/contract/editor' data-editor-page='history.html' data-toggle='tooltip' data-placement='top' title='查看签到历史'> <i class='fa fa-eye'></i> </a>";
			
			if(authstr.indexOf("miwawa.esm.contract.remove") > -1){
	 			operator += "<a class='btn btn-danger  btn-xs btn-table-op' onclick='handlerRemove(this,\""+row.id+"\")' data-table-source='#table-contract' data-form-source='#remove-form-contract' data-toggle='tooltip' data-placement='top' title='删除'> <i class='fa fa-trash'></i> </a>";
	 		}
		}	
		return operator;
	}
	
	/* ===================================== */
	/* 新增及编辑页面 */
	/* ===================================== */
	// 购买信息模版辅助函数
	function helperStudent(customerid){
		return {
			"_student":function(value){
				require(['jquery.plugin.form'],function(form){
					form.chosen("#student").select("#student",{querys:{"customerId_EQ":customerid}},function(chosen){
						jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
					});
				});
			},
			"_user":function(type){
				return type=="userid"?userid:username;
			}
		};
	}
	
	function helperBuyinfo(){
		return {
			"_type":function(value){
				require(['jquery.plugin.form'],function(form){
					form.chosen("#type").select("#type",{"querys":{"pcode_EQ":value.search("托") == -1 ? "c_con_ee_type":"c_con_dc_type"}},function(chosen){
						jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
					});
				});
			},
			"format":function(value, flag){
				switch(flag){
					case "title": return value.search("托") == -1 ? "早教":"托班";
					case "label": return value.search("托") == -1 ? "课时":"月数";
					case "units": return value.search("托") == -1 ? "课时":"个月";
					case "price": return value.search("托") == -1 ? "元/课时":"元/月";
				}
			}
		};
	}
	
	// 购买信息模版辅助函数
	function helperPayinfo(){
		return {
			"_payment":function(value){
				require(['jquery.plugin.form'],function(form){
					form.chosen("#payment").select("#payment",{},function(chosen){
						jQuery("option[value='"+value+"']",chosen).attr("selected","selected").trigger('chosen:updated');
					});
				});
			}
		};
	}
	
	// 表单自动计算按钮事件
	function handlerCalculator(trigger, _form){
		var depend = jQuery(trigger).data("depend");
		var target = jQuery(trigger).data("target");
		var number = 0;
		
		if(depend.multiply){
			var price = 1;
			for(var index in depend.multiply){
				price *= new Number(jQuery("[name='"+depend.multiply[index]+"']", _form).val());
			}
			number = price;
		}else if(depend.addition){
			var total = 0;
			for(var index in depend.addition){
				total += new Number(jQuery("[name='"+depend.addition[index]+"']", _form).val());
			}
			number = total;
		}else if(depend.summation){
			jQuery("[name='"+depend.summation+"']").each(function(i,n){
				number += new Number(jQuery(n).val());
			});
		}else if(depend.percent){
			var discount = jQuery("[name='"+depend.percent.num+"']", _form).val();
			var priceOrig = jQuery("[name='"+depend.percent.den+"']", _form).val();
			if(discount){
				number = new Number(priceOrig)*new Number(discount)/10;
			}else{
				number = new Number(priceOrig);
			}
		}else if(depend.minus){
			for(var index in depend.minus){
				number = Math.abs(number) - jQuery("[name='"+depend.minus[index]+"']", _form).val();
			}
		}
		jQuery("[name='"+target+"']", _form).val(number);
	}
	
	// 修改合同信息后的回调
	function handlerContract(options){
		var fromDate = jQuery("#fromDate",".form-editor-contract").val();
		var overDate = jQuery("#overDate",".form-editor-contract").val();
		jQuery("#fromDate",".form-editor-buyinfo").data("DateTimePicker").date(fromDate);
		jQuery("#overDate",".form-editor-buyinfo").data("DateTimePicker").date(overDate);
	}
	
	function renderFromOver(value, row, index){
		return value+"~"+row.overDate;
	}
	
	function handlerStart(button, rowid, studentid, item){
		var _opts = jQuery(button).data();
		var $form = jQuery(_opts.formSource);
		var $table = jQuery(_opts.tableSource);
		jQuery.ajaxsend({
			url: $form.attr("action").replace("{dbname}", dbname),
			data: _opts.custom ? {
				"id":rowid,"status":"0"
			}:{
				"entityClass":$form.attr("name"),
				"bean":{"id":rowid,"status":"0"}
			},
			success:function(data){
				if(!data.error) {
					jQuery(button).tooltip("destroy");
					$table.bootstrapTable("remove",{field:"id",values:[rowid]});
					$table.bootstrapTable("refresh");
					jQuery.message.success("合同已启用！");
					jQuery.ajaxsend({
						url : "/miwawa/{dbname}/common/search.json".replace("{dbname}",dbname),
						data : {
				       		"entityClass" : "com.app.miwawa.api.esm.entity.view.ContractView",
				          "and[0][operator]": "EQ",
				          "and[0][fieldName]": "studentid",					
				          "and[0][fieldValue]": studentid,						
				          "and[1][operator]": "EQ",
				          "and[1][fieldName]": "item",					
				          "and[1][fieldValue]": item,						
				          "and[2][operator]": "EQ",
				          "and[2][fieldName]": "status",			
				          "and[2][fieldValue]": "finish"
				  	},
				  	success : function(data) {
				  		var contractList = data.rows;
							for(var i=0;i<contractList.length;i++){
								jQuery.ajaxsend({
									url : "/miwawa/{dbname}/common/search.json".replace("{dbname}",dbname),
									data : {
							       		"entityClass" : "com.app.miwawa.api.eam.entity.StudentLeaveLimit",
							          "and[0][operator]": "EQ",
							          "and[0][fieldName]": "contractId",					
							          "and[0][fieldValue]": contractList[i].id				
							  	},
							  	success : function(data) {
							  		var leaveList = data.rows;
										for(var j=0;j<leaveList.length;j++){
											jQuery.ajaxsend({
												url : "/miwawa/{dbname}/common/update".replace("{dbname}",dbname),
												data : {
										       		"entityClass" : "com.app.miwawa.api.eam.entity.StudentLeaveLimit",
										       		"bean":{"id":leaveList[j].id,"contractId":rowid}
										  	},
										  	success : function(data) {
										  		jQuery("#table-contract").bootstrapTable("refresh");
										  	}
											});
										}
							  	}
								});
							}
				  	}
					});
					if(_opts.callback) window[_opts.callback](data);
				}else{
					jQuery.message.warning(data.error);
				}
			}
		});
		
	}
//-->
/*]]>*/
</script>